import { topCategory } from '@/api/topCategory'
import { getHeadCategoryListAPI } from '@/api/home'
export default {
  namespaced: true,
  state: () => {
    return {
      list: topCategory.map(item => ({ name: item }))
    }
  },
  mutations: {
    setCategoryList (state, headCategory) {
      state.list = headCategory
    },
    show (state, item) {
      const category1 = state.list.find(sub => sub.id === item.id)
      category1.open = true
    },
    hide (state, item) {
      const category1 = state.list.find(sub => sub.id === item.id)
      category1.open = false
    }
  },
  actions: {
    async getCategoryList ({ commit }) {
      const { result } = await getHeadCategoryListAPI()
      result.forEach(item => {
        item.open = false
      })
      // console.log(result)
      commit('setCategoryList', result)
    }
  }
}
